<?php

defined('SYSPATH') or die('Access error!');

/**
 * 用户中心的基类
 * ============================================================================
 * 功能描述： 
 *      初始化用户中心的导航等操作
 * ============================================================================
 * $Author: liuxudong $
 */
class Controller_User_Main extends Controller_Main
{

    public function before()
    {
        parent::before();
        if (!$this->logged_in())
        {
            
            $this->request->redirect('user/login'.$this->redirect_url());
        }
        $this->template = Template::instance('user');
        /**
         * 切换用户中心模板(设置用户后台可以自由切换,功能已好，不过暂时不需要设置。用户中心先用默认模板)
         * if (isset($this->user_detail['theme']) && $this->user_detail['theme'] != '')
          {
          $this->template->template_dir = ROOT_PATH . 'themes/user/' . $this->user_detail['theme'] . '/templates';
          $this->template->cache_dir = ROOT_PATH . 'themes/user/' . $this->user_detail['theme'] . '/caches';
          $this->template->compile_dir = ROOT_PATH . 'themes/user/' . $this->user_detail['theme'] . '/templates_c';
          $this->template->cache_lifetime = 3600;
          $this->template->caching = FALSE;
          $this->template->media_path = 'themes/user/' . $this->user_detail['theme'] . '/templates/';
          }
          else
          {
          $this->template = Template::instance('user');
          }* */
        $this->template->assign('user_nav', $this->user_nav());
        //获取用户的基本资料
        $user_detail = Model::factory('user')->get_user_info_by_id($this->user_detail['id']);
        $this->user_detail = $user_detail;
        $this->template->assign('user_detail', $user_detail);

        //左侧导航的选中状
        $current_url = URL::site($this->request->directory . '/' . $this->request->controller . '/' . $this->request->action);
        $this->template->assign('current_selected', $current_url);
        I18n::set_current_file('user');
    }

    public function after()
    {
        //用户中心获取氿上动态
        $jsw_dynamic_news = Model::factory('news')->get_allnews_list_by_category_id(55, 4);
        $this->template->assign('jsw_dynamic_news', $jsw_dynamic_news['list']);
        //获取站内信的数量
        parent::after();
    }

    public function user_nav()
    {
        $user_nav_arr = array(
            array('name' => '基本资料', 'url' => URL::site(Route::get('shop/seller/goods')->uri(array('action' => 'add'))),
                'item' => array(
                    array('name' => '修改基本信息', 'url' => URL::site('user/base/profile')),
                    array('name' => '修改密码', 'url' => URL::site('user/base/password')),
                    array('name' => '修改联系方式', 'url' => URL::site('user/base/contact')),
                    array('name' => '修改头像', 'url' => URL::site('user/base/avatar')),
                    // array('name' => '更换风格', 'url' => URL::site(Route::get('userinfo')->uri(array('action' => 'theme')))),
                    //array('name' => '公司相关', 'url' => URL::site(Route::get('usercompany')->uri(array('action' => 'profile')))),
                    array('name' => '站内信', 'url' => URL::site('user/message/receive_new')),
                    array('name' => '我的收藏', 'url' => URL::site('user/collect/list')),
                    array('name' => '账户财产', 'url' => URL::site('user/account/amount'),
                        'item' => array(
                            array('name' => '积分日志', 'url' => URL::site('user/account/points')),
                            array('name' => 'RMB日志', 'url' => URL::site('user/account/amount')),
                            array('name' => '经验日志', 'url' => URL::site('user/account/experience')),
                    )),
            )),
            array('name' => '我的问答', 'url' => '#',
                'item' => array(
                    array('name' => '提问', 'url' => URL::site('user/q2a/question/all')),
                    array('name' => '回复', 'url' => URL::site('user/q2a/answer/list')),
            )),
            array('name' => '我的供求', 'url' => '#',
                'item' => array(
                    array('name' => '我的任务', 'url' => URL::site('user/trade/supply')),
                    array('name' => '我的需求', 'url' => URL::site('user/trade/demand')),
                    array('name' => '我的申请', 'url' => URL::site('user/trade/comments')),
            )),
            array('name' => '我的商城', 'url' => URL::site(Route::get('shop/seller/goods')->uri(array('action' => 'add'))),
                'item' => array(
                    array('name' => '我是买家', 'url' => URL::site(Route::get('shop/buyer/order')->uri(array('action' => 'list')))),
                    array('name' => '我是卖家', 'url' => URL::site(Route::get('shop/seller/order')->uri(array('action' => 'list')))),
            )),
        );
        return $user_nav_arr;
    }

    public function set_define_position($word = '', $url = '')
    {
        Breadcrumbs::add('用户中心', URL::site('user/base/index'));
        parent::set_define_position($word, $url);
    }

}